@vs palette_vs
uniform vs_params {
    mat4 mvp;
};

layout(location=0) in vec2 v_pos;
layout(location=1) in vec2 v_uv;
layout(location=2) in float v_palette;

out vec2 texcoord;
flat out int palette_index;

void main() {
    texcoord = v_uv;
    palette_index = int(v_palette);
    gl_Position = mvp * vec4(v_pos.xy, 0.0, 1.0);
}
@end

@fs palette_fs

uniform texture2D uTexture;
uniform sampler uTextureS;
uniform texture2D uPalette;
uniform sampler uPaletteS;

in vec2 texcoord;
flat in int palette_index;
out vec4 FragColor;

void main() {
    float texsample = texture(sampler2D(uTexture, uTextureS), texcoord).r * 255.0f;
    FragColor = texture(sampler2D(uPalette, uPaletteS), vec2(texsample / 4.0, float(palette_index) / 64.0));
}
@end

@program palette palette_vs palette_fs